package health.lm.com.shop.adapter;

import android.annotation.SuppressLint;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jakewharton.rxbinding2.view.RxView;
import com.vondear.rxtool.RxTimeTool;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.router.ARouterConstant;
import health.lm.com.shop.R;
import health.lm.com.shop.entity.HLCompanyLeaderSectionEntity;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.adapter
 * Date：2019/8/13 17:19
 * Introduce：商会领导
 */
public class HLCompanyLeaderAdapter extends BaseSectionQuickAdapter<HLCompanyLeaderSectionEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HLCompanyLeaderAdapter(List<HLCompanyLeaderSectionEntity> data) {
        //super(R.layout.layout_text, R.layout.hl_activity_people_item, data);
        super(R.layout.hl_activity_people_item, R.layout.hl_activity_company_leader_head, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, HLCompanyLeaderSectionEntity item) {
        helper.setText(R.id.textView56, item.header);
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @SuppressLint("CheckResult")
    @Override
    protected void convert(BaseViewHolder helper, HLCompanyLeaderSectionEntity item) {
        String time = RxTimeTool.date2String(new Date(Long.parseLong(item.t.getAttention_time())),
                new SimpleDateFormat("yyyy-MM-dd"));
        ImageLoaderHelper.getInstance().load(mContext, item.t.getAvatar(), helper.getView(R.id.imageView3));
        helper.setText(R.id.textView4, item.t.getName())
                .setText(R.id.textView9, item.t.getTag())
                .setText(R.id.textView5, item.t.getPhone())
                .setText(R.id.textView6, "关注时间：" + time)
                .setGone(R.id.textView7, false)
                .setGone(R.id.textView8, false)
                .setGone(R.id.imageView4, true)
        ;
        RxView.clicks(helper.getView(R.id.imageView4)).throttleFirst(1, TimeUnit.SECONDS).subscribe(v -> {
            ARouter.getInstance().build(ARouterConstant.HLChatActivity)
                    .withString("id", item.t.getId() + "")
                    .withString("name", item.t.getName())
                    .navigation();
        });
    }
}
